<template>
	<view class="home-page">
		<u-navbar bgColor="transparent" titleStyle="color:#fff" title="首页" leftIcon="" :placeholder="true">
		</u-navbar>
		<view class="home-swiper">
			<u-swiper height="300rpx"  bgColor="rgba(0,0,0,0.0)" :list="swiperlist" @change="change"></u-swiper>
		</view>
		<view class="home-noc">
			<image src="../../static/home/noc-icon.png" mode=""></image>
			<u-notice-bar :text="textarr" @click="gonoc" icon="" color="#d8d8d8" direction="column"
				bgColor="rgba(0,0,0,0.0)"></u-notice-bar>
		</view>
		<view class="factory-box">
			<view class="factory-item" v-for="(item,index) in list" :key="index">
				<view class="item-top">
					<image :src="item.logo" mode=""></image>
					<view class="top-right">
						<view class="right-title">
							{{item.name}}
						</view>
						<view class="refund">
							<view class="refund-item way">
								返款方式
							</view>
							<view class="refund-item">
								每日返本返息
							</view>
						</view>
						<view class="price">
							价格：<text>{{Number(item.price).toFixed(0)}}</text>
						</view>
					</view>
				</view>
				<view class="item-num">
					<view class="num">
						<view>
							{{item.proportion}}
						</view>
						<view class="num-text">
							已出售
						</view>
					</view>
					<view class="num">
						<view>
							{{item.rate}}%
						</view>
						<view class="num-text">
							日产量
						</view>
					</view>
					<view class="num">
						<view>
							{{item.day_rec}}
						</view>
						<view class="num-text">
							日收益
						</view>
					</view>
					<view class="num">
						<view>
							{{item.days}}
						</view>
						<view class="num-text">
							工作时间
						</view>
					</view>
				</view>
				<view class="work">
					<view>
						一个账号可以购买 {{item.purchaseNum}}次
					</view>
					<view class="work-btn" @click="goDetails(item)">
						<u-button style="color: #000;border-radius: 20rpx;"
							color="linear-gradient( 90deg, #C8F673 0%, #98F083 100%)" type="primary"
							text="购买矿机"></u-button>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				swiperlist: [],
				textarr: [],
				list: [],
				info: {},
			}
		},
		onLoad() {
			this.getList()
			this.realname()
			this.noclist()
			this.banner()
		},
		onShow() {
			this.islogin()
			this.$store.dispatch('connectRongCloud')
		},
		methods: {
			banner() {
				let params = {

				}
				this.$Request({
					method: 'POST',
					url: '/api/index/banner',
					data: params
				}).then(res => {
					if (res.code == 1) {
						this.swiperlist = res.data.banna
					}
				})
			},
			gonoc(e) {
				console.log(e)
				uni.navigateTo({
					url: '/pages/home/nocdetails/index?id=' + this.textarr[e].id
				})
			},
			noclist() {
				let params = {

				}
				this.$Request({
					method: 'POST',
					url: '/api/index/indexNoticeList',
					data: params
				}).then(res => {
					if (res.code == 1) {
						console.log(res.data)
						this.textarr = res.data
					}
				})
			},
			realname() {
				let params = {

				}
				this.$Request({
					method: 'POST',
					url: '/api/Personal/myIndex',
					data: params
				}).then(res => {
					if (res.code == 1) {
						this.info = res.data.user
					}
				})
			},
			islogin() {
				let token = uni.getStorageSync('token')
				if (token == '' || token == undefined) {
					uni.showToast({
						title: '请先登录！',
						icon: 'none'
					})
					setTimeout(() => {
						uni.navigateTo({
							url: '/pages/login/index'
						})
					}, 1000)
					return
				}
			},
		
			goDetails(item) {
				if (this.info.real_name_status == 0) {
					uni.showToast({
						title: '请先实名！',
						icon: 'none'
					})
					this.realname()
					return
				}
				uni.navigateTo({
					url: '/pages/factory/details/index?id=' + item.id + '&isshow=false'
				})
				
			},
			change(e) {

			},
			getList() {
				this.$Request({
					method: 'POST',
					url: '/api/Product/productList',
					data: {
						page: 1,
						c_id: 1
					}
				}).then(res => {
					if (res.code == 1) {
						this.list = res.data;
					}
				})
			},
		}
	}
</script>
<style>
	page {
		background: #17191A;
	}
</style>
<style scoped lang="scss">
	.home-page {
		min-height: 100vh;
		background-image: url('../../static/my/my-bg.png');
		background-repeat: no-repeat;
		background-size: 100% 568rpx;
		padding: 30rpx;

		.home-noc {
			background: rgba(113, 241, 144, 0.2);
			height: 92rpx;
			margin-top: 30rpx;
			border-radius: 10rpx;
			display: flex;
			align-items: center;
			padding: 0 20rpx;

			image {
				width: 40rpx;
				height: 40rpx;
			}
		}

		.factory-box {
			margin-top: 30rpx;

			.factory-item {
				position: relative;
				margin-top: 30rpx;
				background: linear-gradient(134deg, rgba(255, 227, 211, 0.06) 0%, rgba(67, 130, 84, 0.26) 100%);
				border: 4rpx solid rgba(108, 233, 137, 0.12);
				padding: 30rpx;
				border-radius: 20rpx;


				.item-top {
					display: flex;
					align-items: center;

					image {
						width: 140rpx;
						height: 140rpx;
						border-radius: 15rpx;
					}

					.top-right {
						color: #FFFFFF;
						margin-left: 20rpx;

						.right-title {
							font-size: 32rpx;
							font-weight: 600;
						}

						.refund {
							margin-top: 10rpx;
							display: flex;
							font-size: 24rpx;
							background: #17191A;
							border-radius: 10rpx;
							overflow: hidden;

							.refund-item {
								padding: 10rpx 15rpx;
							}

							.way {
								background: linear-gradient(90deg, #C8F673 0%, #98F083 100%);
								color: #000;
							}
						}
						.price{
							display: flex;
							align-items: center;
							margin-top: 10rpx;
							color: #A1FFA9;
							font-size: 26rpx;
							text{
								font-size: 32rpx;
							}
						}
						
					}
				}

				.item-num {
					display: flex;
					justify-content: space-around;
					padding: 20rpx 0;
					border-radius: 20rpx;
					color: #fff;
					margin-top: 30rpx;
					text-align: center;

					.num {
						color: #A1FFA9;
						font-size: 32rpx;
						font-weight: 600;
					}

					.num-text {
						color: #999;
						font-size: 24rpx;
						margin-top: 15rpx;
					}
				}

				.work {
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-top: 30rpx;
					color: #999;
					font-size: 24rpx;

					.price {
						color: #A1FFA9;
						font-size: 28rpx;
					}
				}
			}
		}
	}
</style>